<?php
	class kyhantradb
	{
		public function Them($TenKyHanTra = "", $MaHinhThucVay = 0)
		{
			$sql = "INSERT INTO kyhantra(TenKyHanTra, MaHinhThucVay)
						   VALUES('$TenKyHanTra', $MaHinhThucVay)";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaKyHanTra = 0, $TenKyHanTra = "", $MaHinhThucVay = 0)
		{
			$sql = "UPDATE kyhantra 
					SET TenKyHanTra = '$TenKyHanTra',
						MaHinhThucVay = $MaHinhThucVay 
					WHERE MaKyHanTra = $MaKyHanTra";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongHopDongTinDung($MaKyHanTra = 0)
		{
			$sql = "SELECT * FROM hopdongtindung WHERE 1";
			if($MaKyHanTra > 0)
				$sql.= " AND MaKyHanTra = $MaKyHanTra";
				
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Xoa($MaKyHanTra = 0)
		{
			$sql = "DELETE FROM kyhantra 
					WHERE MaKyHanTra = $MaKyHanTra";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM kyhantra";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaKyHanTra = 0, $TenKyHanTra = "", $MaHinhThucVay = 0)
		{
			$sql = "SELECT * 
					FROM kyhantra 
					WHERE 1";
			
			if($MaKyHanTra > 0)
				$sql .= " AND MaKyHanTra = $MaKyHanTra";
				
			if($TenKyHanTra != "")
				$sql .= " AND TenKyHanTra = '$TenKyHanTra'";
				
			if($MaHinhThucVay > 0)
				$sql .= " AND MaHinhThucVay = $MaHinhThucVay";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>